<template>
  <view>
    <block v-if="!globalUtils.empty(VIP)">
      <view class="my_vip_self">您当前：{{ !globalUtils.empty(cook_grade_title) ? cook_grade_title : '游客' }}</view>
      <view class="viplist">
        <view class="zdcon">
          <view class="ul">
            <view v-for="(item, idx) in VIP" :key="idx" :class="'li vipli ' + (idx == def_grade ? 'ed' : '')"
                  :data-idx="idx" @tap="vipliFn">
              <image :src="item.LI.grade_ico" mode="aspectFill"></image>

              <view class="h1">{{ item.LI.title }}</view>

              <view class="h2">
                <text v-if=" item.LI.day !== '9999天'">{{ item.LI.day }}</text>
                <text v-else>不限时</text>
              </view>
              <view class="h3">{{ item.LI.price }}</view>

              <view v-if=" item.LI.day !== '9999天'" class="h4">{{ item.LI.price_day }}</view>
            </view>
          </view>
        </view>
      </view>
      <view class="btmbox">
        <button class="btn5 online" type="button" @tap="payFn">在线支付购买</button>
        <!--<button class="btn5 hnpay" type="button" @tap="payhnFn">联系经纪人购买</button>-->
      </view>
      <view class="vipC">
        <view class="h1">套餐说明</view>
        <rich-text :nodes="VIP[def_grade].vipC" class="CC"></rich-text>
      </view>
      <view :style="'height:' + more_height + ';'" class="vipBNR">
        <view class="h1">专享特权</view>
        <view id="ul" class="ul auth">
          <view v-for="(item, index) in VIP[def_grade].text" :key="index" class="dl">
            <view class="dt">
              <text class="i ico"></text>
            </view>

            <view class="dd">
              <rich-text :nodes="item.c"></rich-text>
            </view>
          </view>
        </view>
        <view class="icobg ico"></view>
        <view class="i ico morebtn2 on" @tap="moreFn">{{ morebtn_ico }}</view>
      </view>
    </block>
    <view class="blank"></view>
  </view>
</template>
<script>
import globalUtils from "../../res/www.a9a.cn";

var o;
var t = require('../../res/www.a9a.cn.js');
var app = getApp();
export default {
  computed: {
    globalUtils() {
      return globalUtils
    }
  },
  data() {
    return {
      more_height: '330rpx',
      morebtn_ico: '展开更多特权 ',
      morebtn_onoff: 'off',
      color: '',
      rgbcolor: '',
      VIP: '',
      def_grade: '',
      cook_grade_title: '',
      ios_ifpay: '',
      ifagree: false,
      vipC: '',
      text: []
    };
  },
  onLoad: function (options) {
    var that = this;
    app.globalData.get_openid().then(function (n) {
      that.setData({
        color: app.globalData._ZEAI.color,
        rgbcolor: t.c16_rgb(app.globalData._ZEAI.color)
      });
      app.globalData.chklogin().then(function (t) {
        if (t) {
          (o = uni.getStorageSync('COOK_U')),
              app.globalData.ajax({
                url: 'my.php',
                data: {
                  submitok: 'my_vip',
                  openid: o.openid
                },
                success: function (o) {
                  if (1 == o.flag) {
                    1 != o.ios_ifpay.flag
                        ? uni.getSystemInfo({
                          success: function (t) {
                            if ('ios' == t.platform) {
                              uni.showModal({
                                title: '温馨提示',
                                content: o.ios_ifpay.tips,
                                confirmColor: that.color,
                                cancelText: '返回',
                                confirmText: '联系经纪人',
                                success: function (o) {
                                  if (o.confirm) {
                                    uni.redirectTo({
                                      url: '/myPages/hongniang/hongniang'
                                    });
                                  } else {
                                    if (o.cancel) {
                                      uni.navigateBack();
                                    }
                                  }
                                }
                              });
                            } else {
                              that.setData({
                                VIP: o.VIP,
                                def_grade: o.def_grade,
                                cook_grade_title: o.cook_grade_title,
                                ios_ifpay: o.ios_ifpay
                              });
                            }
                          }
                        })
                        : that.setData({
                          VIP: o.VIP,
                          def_grade: o.def_grade,
                          cook_grade_title: o.cook_grade_title,
                          ios_ifpay: o.ios_ifpay
                        });
                    if (options.vipType) {
                      that.def_grade = options.vipType;
                      console.log('1', options.vipType);
                    }
                    console.log(that.def_grade);
                  } else {
                    'noreg' == o.flag
                        ? uni.navigateTo({
                          url: '/pagesA/reg/reg'
                        })
                        : uni.showModal({
                          title: '',
                          content: o.msg,
                          confirmColor: that.color,
                          cancelText: '返回',
                          confirmText: '联系经纪人',
                          success: function (o) {
                            o.confirm
                                ? uni.redirectTo({
                                  url: '/myPages/hongniang/hongniang'
                                })
                                : o.cancel && uni.navigateBack();
                          }
                        });
                  }
                }
              });
        } else {
          uni.redirectTo({
            url: '/pages/login/login'
          });
        }
      });
    });
  },
  methods: {
    moreFn: function (o) {
      if ('off' == this.morebtn_onoff) {
        this.setData({
          morebtn_onoff: 'on',
          morebtn_ico: '收起 ',
          more_height: 'auto'
        });
      } else {
        this.setData({
          morebtn_onoff: 'off',
          morebtn_ico: '展开更多特权 ',
          more_height: '330rpx'
        });
      }
    },

    vipliFn: function (o) {
      var t = o.currentTarget.dataset.idx;
      this.setData({
        def_grade: t
      });
      console.log('切换套餐', this.def_grade);
    },

    payFn: function () {
      var that = this;
      1 != that.ios_ifpay.flag
          ? uni.getSystemInfo({
            success: function (t) {
              'ios' == t.platform
                  ? uni.showModal({
                    title: '温馨提示',
                    content: that.ios_ifpay.tips,
                    confirmColor: that.color,
                    cancelText: '返回',
                    confirmText: '联系经纪人',
                    success: function (o) {
                      o.confirm
                          ? uni.redirectTo({
                            url: '/myPages/hongniang/hongniang'
                          })
                          : o.cancel && uni.navigateBack();
                    }
                  })
                  : app.globalData.pay({
                    data: {
                      submitok: 'my_vip',
                      grade: that.def_grade
                    }
                  });
            }
          })
          : app.globalData.pay({
            data: {
              submitok: 'my_vip',
              grade: that.def_grade
            }
          });
    },

    payhnFn: function () {
      uni.navigateTo({
        url: '/myPages/hongniang/hongniang'
      });
    },

    ifagreeFn: function (o) {
      1 == o.detail.value
          ? this.setData({
            ifagree: true
          })
          : this.setData({
            ifagree: false
          });
    },

    ifagree_passFn: function () {
      uni.showToast({
        title: '请先点击同意《用户协议》和《隐私条款》',
        icon: 'none',
        mask: true,
        duration: 3000
      });
    }
  }
};
</script>
<style>
@import 'my_vip.css';
</style>
